package com.wf.controller;

import com.wf.domain.ApartmentInfo;
import com.wf.service.ApartmentInfoService;
import com.wf.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * 公寓信息接口
 * @author mpk
 * @since 2024/8/4 11:50:47
 */
@RestController
@RequestMapping("/app/apartment")
@CrossOrigin
@Slf4j
public class ApartmentController {

    /**
     * 注入的公寓信息服务，用于获取公寓信息的业务逻辑
     */
    @Autowired
    ApartmentInfoService apartmentInfoService;

    /**
     * 根据ID获取公寓信息
     * <p>通过GET请求，使用路径变量{@code id}来指定需要查询的公寓ID，返回相应的公寓信息</p>
     *
     * @param id 公寓的ID
     * @return 包含公寓信息的Result对象
     */
    @GetMapping("/{id}")
    @Cacheable(value = "apartment",key = "#id")
    public Result getApartment(@PathVariable  String id)
    {
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(id);
        return Result.success(apartmentInfo);
    }

}
